$(document).ready(function () {



    layui.use(function () {
        dropdown = layui.dropdown

        initSubMenu();
        honorWall()

    });
})

var dropdown = null;
var params = {};//查询条件参数


function honorWall() {

    $('.contain')
        .empty()
        .append(
            new ST()
                .project(1)
                .reduce((x, y) => {
                    return x +
                        `<div class="honor">
                        <div class="honor-title">${y.name}
                            <button class="layui-btn honor-switch" id="dropdown-${y.type}">
                                <span id="span-${y.type}"></span>
                                <i class="layui-icon layui-icon-down layui-font-12"></i>
                            </button>
                        </div>
                        <div class="honor-con" id="honor-con-${y.type}">
                        </div>
                    </div>`
                }, '')
        )

    queryProject()

}


// 查询项目下拉框
function queryProject() {

    new ST()
        .project(1)
        .forEach(item => {

            new ST().trainProject(1, null, null, item.type).then(res => {
                var data = []
                if (res) {
                    data = res
                }
                var dropData = []

                data.forEach(element => {
                    dropData.push(
                        {
                            title: element.name,
                            id: element.id
                        }
                    )
                });


                dropdown.render({
                    elem: '#dropdown-' + item.type,
                    data: dropData,
                    click: function (obj) {
                        this.elem.html(obj.title);

                        queryHonerData(item.type, obj.id)
                    }
                });

                if (dropData.length > 0) {
                    $('#span-' + item.type).html(dropData[0].title)
                    queryHonerData(item.type, dropData[0].id)

                } else {
                    $('#span-' + item.type).html('暂无项目')
                }



            })



        });

}



function queryHonerData(type, id) {

    new AjaxChain()
        .setUrl('/train/score/person/top')
        .setData({
            trainType: type,
            projectId: id,
            top: 3
        })

        .then(data => {

            $('#honor-con-' + type)
                .empty()
                .append(
                    data.reduce(
                        (x, y, index) => {

                            let str = ''
                            switch (index) {
                                case 0:
                                    str = `<span style="color: rgba(252, 229, 80, 1);">第一名</span>`
                                    break;
                                case 1:
                                    str = `<span style="color: rgba(250, 254, 201, 1);">第二名</span>`
                                    break;
                                case 2:
                                    str = `<span style="color: rgba(80, 226, 252, 1);">第三名</span>`
                                    break;

                                default:
                                    break;
                            }


                            if (type == 3) {
                              
                                return x +
                                    `<div class="honor-gun">
                                            ${str}
                                        <div>
                                            <li>队伍名称：${y.teamName || ''}</li>
                                            <li>成绩：${y.minTime}s</li>
                                        </div>
                                    </div>`

                            } else {

                                return x +
                                    `<div class="honor-item">
                                    <img src="${y.photoPath ? ('/images/' + y.photoPath) : '../static/img/photo1.png'}">
                                    <div>
                                        ${str}
                                        <li>姓名：${y.personName || ''}</li>
                                        <li>成绩：${y.minTime}s</li>
                                    </div>
                                </div>`
                            }


                        }, ''
                    )
                )


        })
        .send();

}
